package com.xajh.duoduo.eunm.position;

import com.xajh.duoduo.config.NumConfig;
import com.xajh.duoduo.environment.CurrentRolePosition;
import com.xajh.duoduo.environment.Environment;
import com.xajh.duoduo.eunm.process.ProcessEnum;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public enum RolePosition {
    Role_0(125,85,"RolePosition1"),
    Role_1(85,140,"RolePosition2"),
    Role_2(60,210,"RolePosition3"),
    Role_3(60,280,"RolePosition4"),
    Role_4(85,340,"RolePosition5"),

    Role_5(775,80,"RolePosition6"),
    Role_6(730,140,"RolePosition7"),
    Role_7(710,210,"RolePosition8"),
    Role_8(710,280,"RolePosition9"),
    Role_9(735,340,"RolePosition10"),

    Role_10(1425,70,"RolePosition11"),
    Role_11(1380,125,"RolePosition12"),
    Role_12(1360,195,"RolePosition13"),
    Role_13(1360,265,"RolePosition14"),
    Role_14(1385,330,"RolePosition15"),

    Role_15(125,465,"RolePosition16"),
    Role_16(80,525,"RolePosition17"),
    Role_17(60,595,"RolePosition18"),
    Role_18(60,665,"RolePosition19"),
    Role_19(85,725,"RolePosition20"),

    Role_20(775,465,"RolePosition21"),
    Role_21(730,525,"RolePosition22"),
    Role_22(710,595,"RolePosition23"),
    Role_23(710,665,"RolePosition24"),
    Role_24(735,725,"RolePosition25");


    private int x;
    private int y;
    private String comment;

    RolePosition(int x, int y, String comment) {
        this.x = x;
        this.y = y;
        this.comment = comment;
    }

    public RolePosition getNextAndSetCurrentRolePosition(){
        Map<Integer, List<RolePosition>> rolesGroup = CurrentRolePosition.getRolesGroup();
        Integer currentGroupIndex = CurrentRolePosition.getGroupIndex();
        Integer currentItemIndex = CurrentRolePosition.getItemIndex();

        int nextGroupIndex;
        int nextItemIndex;
        /**例：当前为1组2号位
         * 这个方法返回的应该是1组3号位
         * 但是，设置的currentRole，应该是2组2号位
         * 因为当前账号需要移动到下方点击角色进入游戏，换号后需要从对应的2组2号位选下一个，即2组3号位
         * */
        //设置下一组的currentRole
        //最后一组 且 不是最后一个
        if((currentGroupIndex + 1) == NumConfig.deviceNum && (currentItemIndex + 1) != NumConfig.roleNum){
            nextGroupIndex = 0;
            nextItemIndex = currentItemIndex + 1;
        }
        //最后一组 且 是最后一个
        else if((currentGroupIndex + 1) == NumConfig.deviceNum && (currentItemIndex + 1) == NumConfig.roleNum){
            nextGroupIndex = 0;
            nextItemIndex = 0;
        } else{
            nextGroupIndex = currentGroupIndex + 1;
            nextItemIndex = currentItemIndex;
        }

        //设置现在的位置
        CurrentRolePosition.setCurrentRolePosition(new AtomicReference<>(rolesGroup.get(nextGroupIndex).get(nextItemIndex)));
        CurrentRolePosition.setGroupIndex(nextGroupIndex);
        CurrentRolePosition.setItemIndex(nextItemIndex);

        //返回当前组的下一个角色来 进入游戏
        //如果当前组，已经是最后一个了。则返回null
        if((currentItemIndex + 1) == NumConfig.roleNum){
            return null;
        }
        return rolesGroup.get(currentGroupIndex).get(currentItemIndex + 1);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }
}
